package com.zhuannimei;


import net.tsz.afinal.FinalDb;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import cn.jpush.android.api.JPushInterface;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.zhuannimei.service.ZnmService;
import com.zhuannimei.utility.PersistTool;

public class GlobalApplication extends Application {

	public static FinalDb appDB;// 数据库操作类
	private static final String TAG = "GlobalApplication";
	private static final String targetDirectory = null;
	private static final String dbName = "zhuan.db";
	public static Context mContext;
	@Override
	public void onCreate() {
		super.onCreate();
		mContext = this;
		init();
		initImageLoader(this);
	}

	public void init() {
		PersistTool.init(getApplicationContext());
		appDB = FinalDb.create(mContext, targetDirectory, dbName);
		
		JPushInterface.setDebugMode(true); 	//设置开启日志,发布时请关闭日志
        JPushInterface.init(getApplicationContext());     		// 初始化 JPush
        //开启服务 
//        startService(new Intent(getApplicationContext(),ZnmService.class));
	}

	public static void initImageLoader(Context context) {
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.denyCacheImageMultipleSizesInMemory()
				.discCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO)
				.writeDebugLogs() // Remove for release app
				.build();
		ImageLoader.getInstance().init(config);
	}
	
}
